In [1]:
require 'daru/view'
Out[1]:
In [2]:
Daru::View.plotting_library = :googlecharts
Out[2]:
In [3]:
data = [
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]
pie_chart_table = Daru::View::Table.new(data)
pie_chart_table.show_in_iruby
Out[3]:
In [4]:
pie_chart_options = {
type: :pie, height: 400, title: 'My Daily Activities'
}
pie_chart_chart = Daru::View::Plot.new(pie_chart_table.table, pie_chart_options)
pie_chart_chart.show_in_iruby
Out[4]:
In [5]:
pie_chart3D_options = {
type: :pie, height: 400, title: 'My Daily Activities', is3D: true
}
pie_chart3D = Daru::View::Plot.new(pie_chart_table.table, pie_chart3D_options)
pie_chart3D.show_in_iruby
Out[5]:
In [6]:
pie_chart_dount_options = {
type: :pie, height: 400, title: 'My Daily Activities',pieHole: 0.4,
}
pie_chart_dount = Daru::View::Plot.new(pie_chart_table.table, pie_chart_dount_options)
pie_chart_dount.show_in_iruby
Out[6]:
In [7]:
pie_chart_dount_options = {
type: :pie, height: 400, title: 'My Daily Activities',pieHole: 0.5,
pieSliceTextStyle: {
color: 'black',
},
legend: 'none'
}
pie_chart_dount = Daru::View::Plot.new(pie_chart_table.table, pie_chart_dount_options)
pie_chart_dount.show_in_iruby
Out[7]:
In [8]:
data = [
['Language', 'Speakers (in millions)'],
['German', 5.85],
['French', 1.66],
['Italian', 0.316],
['Romansh', 0.0791]
]
pie_chart_rotate_table = Daru::View::Table.new(data)
pie_chart_rotate_table.show_in_iruby
Out[8]:
In [9]:
pie_chart_rotate_options = {
type: :pie, height: 500
}
pie_chart_rotate_dount = Daru::View::Plot.new(pie_chart_rotate_table.table, pie_chart_rotate_options)
pie_chart_rotate_dount.show_in_iruby
Out[9]:
In [10]:
pie_chart_rotate_options = {
legend: 'none',
pieSliceText: 'label',
title: 'Swiss Language Use (100 degree rotation)',
pieStartAngle: 100,type: :pie, height: 500
}
pie_chart_rotate_dount = Daru::View::Plot.new(pie_chart_rotate_table.table, pie_chart_rotate_options)
pie_chart_rotate_dount.show_in_iruby
Out[10]:
In [11]:
data = [
['Language', 'Speakers (in millions)'],
['Assamese', 13], ['Bengali', 83], ['Bodo', 1.4],
['Dogri', 2.3], ['Gujarati', 46], ['Hindi', 300],
['Kannada', 38], ['Kashmiri', 5.5], ['Konkani', 5],
['Maithili', 20], ['Malayalam', 33], ['Manipuri', 1.5],
['Marathi', 72], ['Nepali', 2.9], ['Oriya', 33],
['Punjabi', 29], ['Sanskrit', 0.01], ['Santhali', 6.5],
['Sindhi', 2.5], ['Tamil', 61], ['Telugu', 74], ['Urdu', 52]
]
pie_chart_slice_table = Daru::View::Table.new(data, pageSize: 5)
pie_chart_slice_table.show_in_iruby
Out[11]:
In [12]:
pie_chart_slice_options = {
type: :pie, height: 500
}
pie_chart_slice = Daru::View::Plot.new(pie_chart_slice_table.table, pie_chart_slice_options)
pie_chart_slice.show_in_iruby
Out[12]:
In [13]:
pie_chart_slice_options = {
title: 'Indian Language Use',
legend: 'none',
pieSliceText: 'label',
slices: { 4 => {offset: 0.2},
12 => {offset: 0.3},
14 => {offset: 0.4},
15 => {offset: 0.5},
},
type: :pie, height: 500
}
pie_chart_slice = Daru::View::Plot.new(pie_chart_slice_table.table, pie_chart_slice_options)
pie_chart_slice.show_in_iruby
Out[13]:
In [14]:
idx = Daru::Index.new ['Pac Man', 'Percentage']
data_rows = [
['', 75],
['', 25]]
df_pac_man = Daru::DataFrame.rows(data_rows)
df_pac_man.vectors = idx
df_pac_man
Out[14]:
In [15]:
pie_pac_chart = Daru::View::Plot.new(df_pac_man, type: :pie)
pie_pac_chart.show_in_iruby
Out[15]:
In [16]:
opts = {
legend: 'none',
pieSliceText: 'none',
pieStartAngle: 135,
tooltip: { trigger: 'none' },
slices: {
0 => { color: 'yellow' },
1 => { color: 'transparent' }
},
type: :pie
}
pie_pac_chart = Daru::View::Plot.new(df_pac_man, opts)
pie_pac_chart.show_in_iruby
Out[16]:
In [17]:
idx = Daru::Index.new ['Pizza', 'Populartiy']
data_rows = [
['Pepperoni', 33],
['Hawaiian', 26],
['Mushroom', 22],
['Sausage', 10], # Below limit.
['Anchovies', 9] # Below limit.
]
df_pizza = Daru::DataFrame.rows(data_rows)
df_pizza.vectors = idx
df_pizza
Out[17]:
In [18]:
opts = {
title: 'Popularity of Types of Pizza',
sliceVisibilityThreshold: 0.2,
type: :pie, height: 400
}
pie_pizza = Daru::View::Plot.new(df_pizza, opts)
pie_pizza.show_in_iruby
Out[18]:
In [ ]: